package com.superpai.view.db;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import com.superpai.common.Constants;

/**
 * @author Devin.Hu
 * @date 2011-8-24
 * @version V1.0
 * @description 购物车数据库辅助类
 */
public class BaseDBHelper extends SQLiteOpenHelper {

	public BaseDBHelper(Context context) {
		super(context, Constants.DBNAME, null, Constants.VERSION);
	}

	public BaseDBHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL("create table mycart (pcode varchar(50) primary key, pname varchar(50) , price varchar(6) , mprice varchar(6), pnum varchar(4) , pimg varchar(50))");
		db.execSQL("create table mystore (pcode varchar(50) primary key, pname varchar(50) , price varchar(6) , pimg varchar(50))");
		db.execSQL("create table category (cid varchar(50) primary key, cname varchar(50) , sequence int)");
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop store if exists mycart");
		db.execSQL("drop store if exists mystore");
		db.execSQL("drop store if exists category");
		onCreate(db);
	} 
}
